package com.eaoa.uc.pubmessage.bo;

import java.util.Iterator;

import com.eaoa.base.EABaseBusinessObject;
import com.eaoa.constants.PubMessageConstants;
import com.eaoa.dao.pub.PubMessageDAO;
import com.eaoa.query.pub.PubMessageQuery;
import com.eaoa.vo.pub.PubMessage;

public class MessageCancelBO extends EABaseBusinessObject {
	private Long messageno;

	private static PubMessageDAO messageDAO = new PubMessageDAO();

	public MessageCancelBO(Long messageno) {
		super();
		this.messageno = messageno;
	}

	
	protected void performBusinessLogic() {
		PubMessage message = (PubMessage) messageDAO.loadAndLock(messageno);
		message.setStatus(PubMessageConstants.MESSAGE_STATUS_NEW);
		messageDAO.update(message);
		
		Long sessionid = message.getSessionid();
		Iterator messageIt = PubMessageQuery.loadBySessionid(sessionid).iterator();
		while(messageIt.hasNext()){
			PubMessage item = (PubMessage)messageIt.next();
			messageDAO.deleteByID(item.getMessageno());
		}
		
	}
}
